/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 10:14:50
 * @LastEditors: upholdjx 1373577124@qq.com
 * @LastEditTime: 2023-07-09 14:42:03
 */
import { getAreaObj } from '@/utils/util'
import { cloneDeep } from 'lodash-es'
// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{
			label:'组织名称',
			prop:'orgName'
		},
		{
			label:'任务名称',
			prop:'taskName'
		},
		{
			label:'执行人',
			prop:'practitioners'
		},
		{
			label:'评估等级',
			prop:'starRating'
		},
		{
			label:'分值结果',
			prop:'fieldRatingScore'
		},
		{
			label:'创建时间',
			prop:'createTime'
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}



export const baseConfig = {
	pageName: '机构等级评定管理',
	// 数据字典
	dictcodes: [''],
	rowKey: 'id',
	addLabel: '新增',
	// 删除插入
	tipLabel: 'taskName',
	exportMqTopic: '/ning/export/',
	api: {
		index: 'view_bscServiceOrgAssess_page_pc',
		detail:'view_bscServiceOrgAssess_view',
		export: 'view_bscServiceOrgAssess_export',
		delete: 'view_bscServiceOrgAssess_del',
		// add: 'view_bscServiceOrgAssess_add',
		edit: 'view_bscServiceOrgAssess_edit',
		import: 'view_bscServiceOrgAssess_import',
	},
	auth: {
		index: 'view_bscServiceOrgAssess_page_pc',
		detail:'view_bscServiceOrgAssess_view',
		export: 'view_bscServiceOrgAssess_export',
		delete: 'view_bscServiceOrgAssess_del',
		// add: 'view_bscServiceOrgAssess_add',
		edit: 'view_bscServiceOrgAssess_edit',
		import: 'view_bscServiceOrgAssess_import',
		// 批量搜索
		mulitSet: 'mulitSet',
	},
	// 当前行操作按钮
	menuBtn: [
		{
			icon: 'detail',
			label: '评估报告',
			type: 'primary',
			operate: 'Report',
			auth: '',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑评估内容',
			type: 'primary',
			operate: 'Assess',
			auth: '',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '详情',
			type: 'primary',
			operate: 'Detail',
			auth: '',
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: 'view_dpNewsInfo_del',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '85%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			// { 
			// 	label:'评估状态',
			// 	prop:'',
			// 	span:8
			// },
			{ 
				label:'评估等级',
				prop:'starRating',
				span:8
			},
			{ 
				label:'执行人',
				prop:'practitionersJson',
				span:8
			},
		],
	},
	// 新增
	formConfig: {
		showBtn: true,
	},
	// 列表
	tableConfig,
	// 详情
	// 处理发布日期
	beforeOnLoadFormate: async (params) => {
		if (params.publishDateBetween) {
			params.publishDateBetween = params.publishDateBetween.join(',')
		}
		if(params.practitionersJson){
			params.practitionersJson= 'name\":\"'+params.practitionersJson
		}
		return Promise.resolve({
			...params,
		})
	},
	operateFormate:async (form,type) =>{
		let item = cloneDeep(form)
		const areasInfo: any = getAreaObj(item, '')
			if(item.practitionersJson){
				let data = JSON.parse(item.practitionersJson)
				let list = data.map(el=>{
					return el.name
				})
				item.practitioners = list.join(',')
			}
			return Promise.resolve({
				...item,
				...areasInfo
			})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areasInfo: any = getAreaObj(item, '')
			if(item.practitionersJson){
				let data = JSON.parse(item.practitionersJson)
				let list = data.map(el=>{
					return el.name
				})
				item.practitioners = list.join(',')
			}
			return {
				...item,
				...areasInfo
			}
		})
		return Promise.resolve(tableData)
	},
	// 新增处理
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, '')
			const params = {
				...form,
				...areasObj,
				areas: undefined,
			}
			resolve(params)
		})
	},
}
